<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <!-- form结构 -->
    <form action="http://ajax-api.itheima.net/api/data" method="post">
      <input type="text" name="username" class="num1" placeholder="请输入用户名" /><br />
      <input type="password" name="password"  class = 'num2' placeholder="请输入密码" /><br />
      <button type="submit">登录</button>
    </form>
    <!-- 引入axios -->
    <script src="./axios.js"></script>
    <script>
      //1.先获取dom
    //  const btn = document.querySelector('button');
     const num1 = document.querySelector('.num1');
     const num2 = document.querySelector('.num2');
     const form = document.querySelector('form');
     form.addEventListener('submit', function(e){
     const username = num1.value.trim() 
     const password = num2.value.trim()
      e.preventDefault()
axios({
  url:'http://ajax-api.itheima.net/api/login',
  method: 'POST',
data:{
  username,
  password,
}
})
.then(({data:res}) => {
  console.log(res);
})

     })
    </script>
  </body>
</html>
